|
|
|
|
|
|
|
Response.Write ("Msgbox " & Chr(34) & sString & Chr(34) & vbCrLf)
Response.Write ("</SCRIPT>" & vbCrLf )
%> |
|
|
|
|
|
|
|
|
The preceding code actually generates VBScript statements that will be executed by the browser. The Response.Write statements execute on the server, causing <SCRIPT> tags and code to be sent back to the browser. In other words, you use code in an ASP page to generate code for the browser. This might seem confusing at first, but if you type in the example and view the source in the browser, it will make more sense. Also, note that you paid particular attention to quotes and carriage returns in the client code, just as if you had entered it manually. |
|
|
|
|
|
|
|
|
One use of server-generated client script is to control an ActiveX object embedded in a Web page. For example, your ASP page could contain the <OBJECT> tag for a list box or other control, plus the dynamically generated statements to add specific data items to it. |
|
|
|
|
|
|
|
|
The Response Object and Other Methods |
|
|
|
|
|
|
|
|
In the security example, you learned about two other methods of the Response object: Redirect and End. The End is used to end the current response to the client, as in this example: |
|
|
|
|
|
|
|
|
<H1> Here is some HTML the browser will see! </H1>
<% Response.End %>
<H1> but the browser will never see this! </H1> |
|
|
|
|
|
|
|
|
The Redirect method is used to ask the browser to move to a new URL, as in the following example: |
|
|
|
|
|
|
|
|
<% Response.Redirect ("http://www.callsomeonewhocares.com/" %> |
|
|
|
|
|
|
|
|
The previous line of code only works if no HTML has been returned. In other words, if you attempt to use Response.Redirect after a Response.Write, an error occurs. |
|
|
|
|
|
|
|
|
One property of the Response object that you should have mentioned in the security section is the Expires property. As you might know, the browser stores everything it reads from the Internet temporarily on your hard drive. This group of temporary files is known as the cache. Certain files, such as graphic images, are ideal for storing in the cache. Others, such as the login page (with name and password), are not. You set the Expires property to the number of minutes you want the page to remain in the cache. For the security page, you would probably want to set it to zero, as in the following example: |
|
|
|
|
|
|
|
|
The Response object is also used to send cookies to the user's browser. Cookies work like session variables but are stored on the client PC. (IIS actually uses cookies to help maintain the session IDs.) Cookies are useful when you want to save personal settings on a user's hard drive and retrieve them later. However, cookies are not guaranteed to be availablea lot of users consider them an invasion of privacy so they disable them. To send a cookie to the user's browser, simply assign a value as you would with a session variable: |
|
|
|
|
|
|
|
|
Response.Cookies("MYCOOKIE") = 1234 |
|
|
|
|
|
|
|
|
A similar Cookies collection used with the Request object is used to retrieve cookie values. |
|
|
|
|
|